package cn.tedu.micro.demo.es.utils;

import cn.tedu.micro.demo.es.po.StudentEsPO;

import java.util.*;

public class StudentDataGenerator {



    /**
     * 生成指定数量的随机学生数据
     */
    public static List<StudentEsPO> generateRandomStudents(int count) {
        List<StudentEsPO> students = new ArrayList<>();
        Random random = new Random();

        for (int i = 0; i < count; i++) {
            students.add(createRandomStudent(random));
        }

        return students;
    }

    /**
     * 生成单个随机学生
     */
    private static StudentEsPO createRandomStudent(Random random) {
        StudentEsPO student = new StudentEsPO();
        student.setId(UUID.randomUUID().toString());
        student.setName(NickNameGenerator.generate());
        student.setAge(18 + random.nextInt(8));
        student.setBirthday(generateRandomBirthday(random));
        student.setProfile("喜欢音乐,喜欢运动,喜欢歌剧");
        return student;
    }

    /**
     * 生成随机生日（1998-2005年）
     */
    private static Date generateRandomBirthday(Random random) {
        // 1998年到2005年
        int year = 1998 + random.nextInt(8);
        int month = random.nextInt(12);
        int day = 1 + random.nextInt(28); // 简单处理，避免月份天数问题

        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month, day);
        return calendar.getTime();
    }
}
